<template>
  <div class="box">
    <h2>01 初步使用图表</h2>
    <hr />
    <div ref="myChart" :style="{ width: '500px', height: '300px' }"></div>
  </div>
</template>

<script>
export default {
  name: 'hello',
  data() {
    return {
      msg: 'Welcome to Your Vue.js App',
      list: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    }
  },
  mounted() {
    this.drawLine()
  },
  methods: {
    drawLine() {
      //  this.$refs.myChart 通过 ref 引用dom元素
      let myChart = this.$echarts.init(this.$refs.myChart)
      // 绘制图表
      myChart.setOption({
        title: { text: '标题' },
        tooltip: {},
        xAxis: {
          data: this.list
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [1, 120, 136, 110, 110, 120]
          }
        ]
      })
    }
  }
}
</script>

<style scoped>
.box {
  overflow: hidden;
  float: left;
  width: 50%;
  height: 400px;
  background: rgb(206, 165, 165);
}
</style>
